// app.js
App({

  // 当小程序初始化完成时自动触发，全局只触发一次
  onLaunch() {
    wx.db = {};
    // 项目url
    wx.db.url = (url)=> {
      return `https://douban-api.uieee.com/${url}`
    }
    // 封装toast
    this.initToast()

    // 获取设备信息
    const info = wx.getSystemInfoSync()
    wx.db.statusBarHeight = info.statusBarHeight
    if (info.platform == 'android') {
      wx.db.navBarHeight = 48
    } else {
      wx.db.navBarHeight = 44
    }    
  },
  
  initToast() {
    const toastTypeNormal = 0;
    const toastTypeError = 1;
    const toastTypeSuccess = 2;
  let commonTaost = (title, type, duration = 1500) => {
    let options = {
      title: title,
      icon: 'none',
      duration: duration
    };
    if (type == toastTypeSuccess) {
      options.icon = 'success'
    } else if (type == toastTypeError) {
      options.image = '/assets/imgs/upsdk_cancel_normal.png'
    }
    wx.showToast(options);
  };
  wx.db.toast = (title, duration) => {
    commonTaost(title, toastTypeNormal, duration)
  };
  wx.db.toastSuccess = (title, duration) => {
    commonTaost(title, toastTypeSuccess, duration)
  };
  wx.db.toastError = (title, duration) => {
    commonTaost(title, toastTypeError, duration)
  };
  },

  // 小程序启动，或从后台进入前台显示时触发
  onShow() {

  },

  // 小程序从前台进入后台时触发
  onHide() {

  },
  
  globalData: {
    userInfo: null
  },
   
})
